package com.zs.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.zs.dto.StudentDto;
import com.zs.entity.StudentInfo;
import com.zs.exception.UnCatchParamException;
import com.zs.exception.ValidateException;
import com.zs.service.StudentService;
import com.zs.util.Result;
import com.zs.util.ResultMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

/**
 * @BelongsProject: springbootdemo
 * @BelongsPackage: com.zs.controller
 * @Author:DuoErGun
 * @CreateTime: 2019-07-17 14:30
 * @Description: 学生控制类
 * @Emil: 381889220@qq.com
 */
@RestController
@RequestMapping("/stu/")
@CrossOrigin
public class StudentController {

    @Resource
    private StudentService studentService;

    /**
     * @param studentDto
     * @return
     */
    @RequestMapping("get")
    public ResultMap onGet(StudentDto studentDto) {
        return new ResultMap(studentService.search(studentDto), studentService.getCount(studentDto));
    }

    /**
     * @param studentInfo
     * @return
     */
    @RequestMapping("insert")
    public Result onAdd(@RequestBody StudentInfo studentInfo) {
        return studentService.insert(studentInfo);
    }

    /**
     * @param ids
     * @return
     */
    @RequestMapping("remove")
    public Result onRemove(String[] ids) {
        return studentService.delete(ids);
    }

    /**
     * 对学生进行修改
     * @param studentInfo 要修改的学生信息
     * @return 修改的结果
     * @throws UnCatchParamException 缺少参数异常
     * @throws ValidateException 数据验证失败异常
     */
    @RequestMapping("modify")
    public Result onModify(@RequestBody StudentInfo studentInfo) throws UnCatchParamException {
        return studentService.update(studentInfo);
    }
}
